/**   
 * @Title: RescAction.java 
 * CopyRight(c)2010-DMX 
 */
package com.dmx.fw.web.struts2.action.system;

import java.io.IOException;
import java.util.Date;
import java.util.List;

import com.dmx.fw.bean.mapping.pojo.Organization;
import com.dmx.fw.bean.mapping.pojo.ParameterData;
import com.dmx.fw.bean.mapping.pojo.Resc;
import com.dmx.fw.service.interfaces.RescService;
import com.dmx.fw.web.struts2.action.BaseAction;

/** 
 * @Description: 某一资源管理项增、删、改值Action
 * @author: zhaojie
 * @date: 2010.4
 * @version V1.0 
 * 
 */
public class RescAction extends BaseAction {
	
	private Resc resc;
	
	private List<Resc> rescList;
	
	private String rescId;
	
	private RescService rescService;
	
	//进入新增输入界面
	public String doAddInput(){
		return "input";
	}
	
	//执行添加提交操作
	public String doAddSubmit() throws Exception{
		String retMsg = this.savaRescData();
		//retMsg="xxxxxxxxxxxxxxx";
		if (retMsg == null){
			//String resultUrl = "system/rescSearch.action";
			this.setSuccessinfo(this.getText("info.addSuccess"));
			
			return "list";
		}
		else{
			this.setAjaxJsonMsgResult(retMsg,null);
		}

		return null;    
	}
	
	//执行修改提交界面
	public String doEditSubmit() throws Exception{
		String retMsg = this.updateRescData();
		if (retMsg == null){
			//String resultUrl = "system/rescSearch.action";
			this.setSuccessinfo(this.getText("info.modifySuccess"));
			//this.setAjaxJsonUrlResult(resultUrl);
			return "list";
		}
		else{
			this.setAjaxJsonMsgResult(retMsg,null);
		}
		return null;
	}
	
	//执行删除操作
	public String doDelete() throws IOException{
		Resc param = new Resc();
		param.setId(resc.getId());
		rescService.delete(param);
		//String resultUrl = "system/rescSearch.action";
		this.setSuccessinfo(this.getText("info.deleteSuccess"));
		//this.setAjaxJsonUrlResult(resultUrl);
		return "list";
	}
	
	/**
	 * 添加项
	 * @return
	 */
	private String savaRescData() {
		Resc param = new Resc();
		//param.setId(resc.getId());
		param.setName(resc.getName());
		param.setResString(resc.getResString());
		param.setMenuSort(resc.getMenuSort());
		param.setStatus(resc.getStatus());
		param.setMenuJust(resc.getMenuJust());
		rescService.create(param);
		return null;
	}

	/**
	 * 修改项
	 * @return
	 */
	private String updateRescData() {
		Resc param = rescService.getResc(resc.getId().toString());
		param.setName(resc.getName());
		param.setResString(resc.getResString());
		param.setMenuSort(resc.getMenuSort());
		param.setStatus(resc.getStatus());
		param.setMenuJust(resc.getMenuJust());
		rescService.update(param);
		return null;
	}
	
	//进入修改输入界面
	public String doEditInput(){
		resc = rescService.getResc(resc.getId().toString());
		return INPUT;
	}
	
	public String rescSearch(){
		return "";
	}
	
	public String getRescs(){
		rescList = rescService.getRescs();
		return "rescs";
	}
	
	public String toAddResc(){
		rescList = rescService.getRescs();
		return "rescAdd";
	}
	
	public String removeResc(){
		rescService.removeObject(resc);
		return "getRescs";
	}
	
	public RescService getRescService() {
		return rescService;
	}

	public void setRescService(RescService rescService) {
		this.rescService = rescService;
	}

	public List<Resc> getRescList() {
		return rescList;
	}

	public void setRescList(List<Resc> rescList) {
		this.rescList = rescList;
	}

	public Resc getResc() {
		return resc;
	}

	public void setResc(Resc resc) {
		this.resc = resc;
	}

	public String getRescId() {
		return rescId;
	}

	public void setRescId(String rescId) {
		this.rescId = rescId;
	}
	
	
}
